home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / vbdatabs / cacheb.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-03-14  |  3.6 KB  |  91 lines

  1. // ------------------------------- //
  2. // -------- Start of File -------- //
  3. // ------------------------------- //
  4. // ----------------------------------------------------------- //
  5. // C++ Header File Name: cacheb.h
  6. // Compiler Used: MSVC40, DJGPP 2.7.2.1, GCC 2.7.2.1, HP CPP 10.24
  7. // Produced By: Doug Gaer   
  8. // File Creation Date: 02/07/1997  
  9. // Date Last Modified: 03/15/1999
  10. // Copyright (c) 1997 Douglas M. Gaer
  11. // ----------------------------------------------------------- // 
  12. // ---------- Include File Description and Details  ---------- // 
  13. // ----------------------------------------------------------- // 
  14. /*
  15. The VBD C++ classes are copyright (c) 1997, by Douglas M. Gaer.
  16. All those who put this code or its derivatives in a commercial
  17. product MUST mention this copyright in their documentation for
  18. users of the products in which this code or its derivative
  19. classes are used. Otherwise, you have the freedom to redistribute
  20. verbatim copies of this source code, adapt it to your specific
  21. needs, or improve the code and release your improvements to the
  22. public provided that the modified files carry prominent notices
  23. stating that you changed the files and the date of any change.
  24.  
  25. THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND.
  26. THE ENTIRE RISK OF THE QUALITY AND PERFORMANCE OF THIS SOFTWARE
  27. IS WITH YOU. SHOULD ANY ELEMENT OF THIS SOFTWARE PROVE DEFECTIVE,
  28. YOU WILL ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR
  29. CORRECTION.
  30.  
  31. The Cacheb class is used as a base class for the Cache class. It
  32. incorporates functions that are independent of the bucket type.
  33. The cache is used to handle requests for file-based objects. The
  34. cache must determine whether an object is already loaded. If the
  35. object is not loaded the cache reserves a bucket and loads the
  36. object into memory. This cache design uses cache pointers to
  37. reference cache buckets directly, with each cache pointer being
  38. initialized after the bucket is reserved. The least-recently
  39. reserved cache bucket is overwritten when the cache fills up.
  40. */
  41. // ----------------------------------------------------------- //   
  42. #ifndef __CACHEB_HPP__
  43. #define __CACHEB_HPP__
  44.  
  45. #include "vbdfile.h"
  46.  
  47. class Bucketb; class CachePtrb; // Forward class declarations
  48.  
  49. // Data independent (C)ache (b)ase class
  50. class Cacheb
  51. {
  52. protected:
  53.   Cacheb(Bucketb *b, int n, unsigned bkt_size);
  54.   virtual ~Cacheb();
  55.  
  56. protected:
  57.   Bucketb *AcquireBkt();
  58.   Bucketb *FindBkt(FAU Address);
  59.   void MoveToFront(Bucketb *b);
  60.  
  61. public:
  62.   friend class CachePtrb;
  63.   void Connect(VBDFilePtr &fp) { Clear(); fptr = fp; }
  64.   void Disconnect() { if (fptr) Clear(); fptr = 0; }
  65.   void Flush(int empty_bkts = 0);
  66.   void Clear();
  67.   virtual Bucketb *ReserveBkt(FAU Address, int ensure_loaded=1);
  68.   void FastBind() { FastBinds++; }
  69.   FAU GetHits() { return Hits; }
  70.   FAU GetMisses() { return Misses; }
  71.   FAU GetFastBinds() { return FastBinds; }
  72.   Bucketb *GetHead() { return Head; } 
  73.   int GetBuckets() { return nbuckets; }
  74.   
  75. protected:
  76.   int nbuckets;      // Size of cache
  77.   VBDFilePtr fptr;   // File cache is connected to
  78.   Bucketb *Head;     // Most recently reserved bucket
  79.  
  80.   // Performance statistics members
  81.   FAU Hits;      // Number of buckets that did not have to be acqiured 
  82.   FAU Misses;    // Number of cache buckets that had to acqiured  
  83.   FAU FastBinds; // Binds to previously allocated, unchanged buckets 
  84. };
  85.  
  86. #endif // __CACHEB_HPP__
  87. // ----------------------------------------------------------- // 
  88. // ------------------------------- //
  89. // --------- End of File --------- //
  90. // ------------------------------- //
  91.